package com.ourgame.tankgame.control;

import com.jme3.asset.AssetManager;
import com.jme3.bounding.BoundingBox;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.input.InputManager;
import com.jme3.renderer.Camera;
import com.jme3.scene.Spatial;
import com.ourgame.tankgame.exception.TankGameNullPointException;

/**
 *
 * @author Lcn
 */
public class ControlsManager {

    private static InputManager inputManager;
    private static AssetManager assetManager;
    private static Camera cam;

    public enum ControlType {

        TankControl,}

    public static BarrierControl getBarrierControl(Spatial collisionShapeSpatial) {
        BarrierControl barrierControl = new BarrierControl(CollisionShapeFactory.createDynamicMeshShape(collisionShapeSpatial));
        return barrierControl;
    }

    public static BulletControl getBulletControl(Spatial collisionShapeSpatial, float mass) {
        BoundingBox spatialBound = (BoundingBox) collisionShapeSpatial.getWorldBound();
        BoxCollisionShape bulletShape = new BoxCollisionShape(spatialBound.getExtent(null));
        BulletControl bulletControl = new BulletControl(bulletShape, getAssetManager(), mass);
        return bulletControl;
    }

    /**
     * @deprecated 
     * use getBarrierControl(Spatial s);
     * @return 
     */
    public static BarrierControl getBarrierControl() {
        BarrierControl barrierControl = new BarrierControl();
        return barrierControl;
    }

    public static AssetManager getAssetManager() {
        if (null == assetManager) {
            throw new TankGameNullPointException("assetManager", "WorldManagerState");
        }


        return assetManager;
    }

    public static void setAssetManager(AssetManager assetManager) {
        ControlsManager.assetManager = assetManager;
    }

    public static Camera getCam() {
        if (null == cam) {
            throw new TankGameNullPointException("cam", "WorldManagerState");
        }
        return cam;
    }

    public static void setCam(Camera cam) {
        ControlsManager.cam = cam;
    }

    public static InputManager getInputManager() {
        if (null == inputManager) {
            throw new TankGameNullPointException("inputManager", "WorldManagerState");
        }
        return inputManager;
    }

    public static void setInputManager(InputManager inputManager) {
        ControlsManager.inputManager = inputManager;
    }
}
